<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">

        function get() {
            $.get("./1",{},function (result) {
                alert(JSON.stringify(result));
            })
        }

        function post() {
            var account = {
                accountName:"account_name_x",
                balance:12345678.90,
                note:"note_x"
            }
            $.post({
                url:"./../account",
                contentType:"application/json",
                data:JSON.stringify(account),
                success:function (result) {
                    alert(JSON.stringify(result));
                }
            })
        }

        function put() {
            var account = {
                id:8765,
                accountName: "account_name_x",
                balance: 12345678.90,
                note: "note_x"
            }

            $.ajax({
                url:"./../account",
                type:"PUT",
                contentType: "application/json",
                data: JSON.stringify(account),
                success:function (result) {
                    alert(JSON.stringify(result));
                }
            })
        }

        function del() {
            $.ajax({
                url:"./../account/897",
                type:"DELETE",
                success:function (result) {
                    alert(JSON.stringify(result));
                }
            })
        }

        function post2() {
            var account = {
                accountName: "account_name_x",
                balance: 12345678.90,
                note: "note_x"
            }

            var result = $.post({
                url:"./../account2",
                contentType:"application/json",
                data:JSON.stringify(account),
                success:function (result,status,xhr) {
                    var status = xhr.status;
                    var success = xhr.getResponseHeader("success");
                    if(success === "true"){
                        alert(JSON.stringify(result));
                    }else {
                        var message = xhr.getResponseHeader("message");
                        alert("success:"+success+",message:"+message);
                    }
                }
            })
        }
        // get();
        // post();
        // put();
        // del();
        post2();
    </script>
</head>
<body>

</body>
</html>